import Vue from "vue";
import Vuex from "vuex";
import subjects from "../store/moudules/subjects";
import students from "../store/moudules/students";
import classes from "../store/moudules/classes";
import api from "@/api";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    userInfo: null,
    authMenus: [],
  },
  getters: {
    username: (state) => state.userInfo?.username,
  },
  mutations: {
    SET_USER_INFO(state, payload) {
      state.userInfo = payload;
    },
    SET_AUTH_MENUS(state, payload) {
      state.authMenus = payload;
    },
  },
  actions: {
    async getAuthMenusAsync({ commit }) {
      const res = await api.login.getAuthMenus();
      if (res.code) {
        commit("SET_AUTH_MENUS", res.data);
      }
    },
  },
  modules: {
    subjectsModule: subjects,
    studentsModule: students,
    classesModule: classes,
  },
});
